<head>
  <script type='text/javascript' src='https://www.google.com/jsapi'></script>
  <script type='text/javascript'>
   google.load('visualization', '1', {'packages': ['geochart']});
   google.load('visualization', '1', {packages:['table']});
   google.setOnLoadCallback(drawRegionsMap);
   google.setOnLoadCallback(drawRegionsMap_US);
   

	function drawRegionsMap_US() {
	  <% t = @us_count_per_area_clean %>
      var data = new google.visualization.DataTable();
      data.addRows(<%=t.size%>);
	  
	  data.addColumn('string', 'City');
      data.addColumn('number', 'Calls');
      data.addColumn('string', 'Comment');
	  <% for i in 0...t.size %>
      	data.setValue(<%=i%>, 0, '<%= t[i].areacode_for_us%>');
      	data.setValue(<%=i%>, 1, <%= t[i].sum_calls %>);
      	data.setValue(<%=i%>, 2, '<%= t[i].areacode_for_us%>');
      <% end %>
      
      
	  var options = {};
	  options['region'] = 'US';
	  options['dataMode'] = 'markers';
	  
      var container = document.getElementById('map_us');
      var geochart = new google.visualization.GeoMap(container);
      geochart.draw(data, options);
  	};
  	
    function drawRegionsMap() {
      <% t = @international_count_per_country_number_clean %>
      var data = new google.visualization.DataTable();
      data.addRows(<%=t.size%>);
	  
	  data.addColumn('string', 'City');
      data.addColumn('number', 'Calls');
      data.addColumn('string', 'Comment');
	  <% for i in 0...t.size %>
      	data.setValue(<%=i%>, 0, '<%= t[i].iso_country_code%>');
      	data.setValue(<%=i%>, 1, <%= t[i].sum_calls %>);
      	data.setValue(<%=i%>, 2, '<%= country_name(t[i].iso_country_code)%>');
      <% end %>
      
      
	  var options = {};
	  //options['region'] = 'US';
	  options['dataMode'] = 'regions';
	  
      var container = document.getElementById('map_international');
      var geochart = new google.visualization.GeoMap(container);
      geochart.draw(data, options);
  };
  
  </script>
</head>
<%= request.request_uri %><br />
<div>
US <br />
<table>
  <tr>
    <th>Area Code</th>
    <th>Total Calls</th>
    <th>ST</th>
  </tr>
  <tr>
  	<td colspan="3">
		<div id="map_us"></div>
    </td>	
  </tr>
<% @us_count_per_area.each do |n| %>
  <tr>
    <td><%= link_to n["identifying_phone_number"], :action=>'detail', :id=>n["identifying_phone_number"], :p=>params[:p], :from=>params[:from], :to=>params[:to], :iso=>n["iso_country_code"] %></td> 
    <td><%= n["sum_calls"] %></td>
    <td><%= n.areacode_for_us %></td>    
    </tr>
<% end %>
</table>
</div>
<br />
<div>
INTERNATIONAL <br />
<table>
  <tr>
    <th>Country Number</th>
    <th>Country Code</th>
    <th>Country Name</th>
    <th>Total Calls</th>
  </tr>
  <tr>
  	<td colspan="4">
		<div id="map_international"></div>
    </td>	
  </tr>
  
<% @international_count_per_country_number.each do |k| %>

  <tr>
    <td><%= link_to k["identifying_phone_number"], :action=>'detail', :id=>k["identifying_phone_number"], :p=>params[:p], :from=>params[:from], :to=>params[:to], :iso=>k["iso_country_code"] %></td>
    <td><%= k["iso_country_code"] %></td> 
    <td><%= country_name k["iso_country_code"] %></td> 
    <td><%= k["sum_calls"] %></td>
    </tr>
<% end %>
</table>
</div>